Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #1, Fixes #2
This PR isn't ready to be merged yet, but I thought it would be okay to have some discussions now.
This PR adds a top-level option
sortPlugins
, enabled by default in Babel 8, to control whether the order provided by the plugin is followed.And added a plugin attribute
orderData
.id
andversion
are so that we can update the plugin order in patch versions, even if users are still using plugins that carry the old order data.The sorting algorithm is very simple. From back to front, all plugins included in the order list are extracted and sorted, and inserted into the location of the first found plugin.
For example, A and B carry order data
[A, B, C, D]
, but C does not.[B,X,A] will be sorted as
[X,A,B]
.Because users almost always use
preset-env
, and presets run behind plugins, this will cause the plugins contained inpreset-env
to be collected at the end, trying to maintain compatibility.This PR also shows an issue #16398 (comment) where our current plugin order breaks some block scoping.
Although this method is not very powerful, it can better maintain compatibility and meet the problems we currently encounter in built-in plug-ins. We can enhance it in Babel 9.
Maybe we should exclude them or use a separate list.